package org.spiderflow.core.expression.reflection;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author zhaoshihao
 * @version 2021/11/11 10:20
 */
class MethodSignature {
    private final String name;
    @SuppressWarnings("rawtypes")
    private final Class[] parameters;
    private final int hashCode;

    @SuppressWarnings("rawtypes")
    public MethodSignature(String name, Class[] parameters) {
        this.name = name;
        this.parameters = parameters;
        final int prime = 31;
        int hash = 1;
        hash = prime * hash + ((name == null) ? 0 : name.hashCode());
        hash = prime * hash + Arrays.hashCode(parameters);
        hashCode = hash;
    }

    @Override
    public int hashCode() {
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        MethodSignature other = (MethodSignature) obj;
        if (!Objects.equals(name, other.name)) {
            return false;
        }
        return Arrays.equals(parameters, other.parameters);
    }
}